home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Comms & Internet / LinkConverter 1.1.2 / Dialog Director v0.7 / Examples / DD Connect To.as < prev    next >
Encoding:
Text File  |  1998-01-12  |  3.9 KB  |  112 lines  |  [TEXT/ToyS]

  1. property history : ["http://www.apple.com", "http://www.hylight.demon.co.uk"]
  2. property dRect : null
  3. property dlog : {bounds:null, name:"Connect To…", closeable:true, style:standard window, contents:[¬
  4.     {class:push button, bounds:[260, 190, 330, 210], font:1, name:"Connect", enabled:5}, ¬
  5.     {class:push button, bounds:[10, 190, 50, 210], name:"Add", enabled:5}, ¬
  6.     {class:push button, bounds:[60, 190, 100, 210], name:"Delete", enabled:4}, ¬
  7.     {class:list box, bounds:[10, 10, 330, 129], font:2, value:1, action:44, flags:2 - 128}, ¬
  8.     {class:text field, bounds:[13, 161, 327, 177]}, ¬
  9.     {class:push button, bounds:[120, 190, 160, 210], name:"Load…"}, ¬
  10.     {class:push button, bounds:[170, 190, 210, 210], name:"Save…"}, ¬
  11.     {class:static text, bounds:[10, 139, 330, 155], contents:"Enter an Internet address (URL):"} ¬
  12.         ]}
  13. property QuitOnConnect : false
  14. --localize these strings:
  15. property OKButton : "OK"
  16. --most error messages should be handled by the OSAX itself:
  17. property generalErrorMessage : "Your Internet software is not configured correctly.  " & ¬
  18.     "Please use the Mac OS installer to re-install your Internet software."
  19.  
  20. if («event GURLiast») is true then
  21.     dd install with fonts [null, {name:"Geneva", size:10}] with greyscale --System, Control, Label, Data
  22.     if dRect = null then
  23.         set bounds of dlog to dd calc dialog bounds [340, 220]
  24.     else
  25.         set bounds of dlog to dRect
  26.     end if
  27.     set d to dd make dialog dlog
  28.     dd set contents of item 4 of d to history
  29.     dd set value of item 4 of d to history's length
  30.     if history's length > 0 then dd set value of item 5 of d to history's item -1
  31.     repeat
  32.         set i to dd interact with user
  33.         if i = 1 then
  34.             if Connect(dd get value of item 5 of d) and QuitOnConnect then exit repeat
  35.         else if i = 2 then -- Add
  36.             set history to history & (dd get value of item 5 of d)
  37.             dd set contents of item 4 of d to history
  38.             dd set value of item 4 of d to history's length
  39.         else if i < 0 then -- Close Window
  40.             exit repeat
  41.         else if i = 6 then -- Load
  42.             try
  43.                 set f to open for access (choose file with prompt "Read URLs from:" of type "TEXT")
  44.                 try
  45.                     if ((get eof f) > 30000) then error -128
  46.                     set history to []
  47.                     repeat
  48.                         set history to history & (read f before return)
  49.                     end repeat
  50.                 on error
  51.                 end try
  52.                 close access f
  53.                 dd set contents of item 4 of d to history
  54.                 dd set value of item 4 of d to history's length
  55.             on error
  56.             end try
  57.         else if i = 7 then -- Save
  58.             try
  59.                 set f to open for access (new file with prompt "Save URLs in:" default name "Connect To URLs") with write permission
  60.                 try
  61.                     set eof f to 0
  62.                     repeat with u in history
  63.                         write u & return to f
  64.                     end repeat
  65.                 on error
  66.                 end try
  67.                 close access f
  68.             on error
  69.             end try
  70.         else
  71.             set n to dd get value of item 4 of d
  72.             if n ≠ 0 then
  73.                 if i = 3 then -- Delete
  74.                     if n = history's length then
  75.                         if n = 1 then
  76.                             set history to []
  77.                         else
  78.                             set history to items 1 thru (n - 1) of history
  79.                         end if
  80.                     else if n = 1 then
  81.                         set history to items 2 thru -1 of history
  82.                     else
  83.                         set history to items 1 thru (n - 1) of history & items (n + 1) thru -1 of history
  84.                     end if
  85.                     dd set contents of item 4 of d to history
  86.                 else if i = 4 then -- List
  87.                     set url to history's item n
  88.                     dd set value of item 5 of d to url
  89.                 else if i = 44 then -- Doubleclick
  90.                     set url to history's item n
  91.                     dd set value of item 5 of d to url
  92.                     if Connect(url) and QuitOnConnect then exit repeat
  93.                 end if
  94.             end if
  95.         end if
  96.     end repeat
  97.     set dRect to dd get bounds of d
  98.     dd uninstall
  99. end if
  100.  
  101. on Connect(url)
  102.     try
  103.         open url (url) with report errors
  104.     on error errorMessage number errorNumber
  105.         if errorNumber = -1708 then --no Internet Scripting Addition osax
  106.             display dialog generalErrorMessage & return & return & " (Error number: " & errorNumber & ¬
  107.                 ")" buttons [OKButton] default button OKButton
  108.         end if
  109.         return false
  110.     end try
  111.     return true
  112. end Connect